﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DTTB.Common;
using DTTB.Domain;

namespace DTTB.DAO
{
    public class PermissionsAllUsersDao : AccessData
    {
        //lấy tất cả PermissionsAllUsers
        public IList<PermissionsAllUsers> GetAllPermissionsAllUsers()
        {
            CommandText = "Select * From TB_PermissionsAllUsers as P Where P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            IList<PermissionsAllUsers> list = CollectionHelper.ConvertTo<PermissionsAllUsers>(table);
            return list;
        }

        //Thêm mới một PermissionsAllUsers
        public bool AddNewPermissionsAllUsers(PermissionsAllUsers permissionsAllUsers)
        {
            return Insert<PermissionsAllUsers>("TB_PermissionsAllUsers", permissionsAllUsers);
        }


        //Xóa tất cả PermissionsAllUsers
        public bool DeleteAllPermissionsAllUsers()
        {
            CommandText = "Delete From TB_PermissionsAllUsers";
            Commandtype = CommandType.Text;

            return Save();
        }


        //Xóa những PermissionsAllUsers có Paths
        public bool DeleteAllPermissionAllUsersByListPathsId(IList<int> listPathsId)
        {
            var stringListPathsId = string.Empty;
            for (int i = 0; i < listPathsId.Count; i++)
            {
                if (i == listPathsId.Count - 1)
                {
                    stringListPathsId += listPathsId[i];
                }
                else
                {
                    stringListPathsId += listPathsId[i] + ",";
                }
            }

            CommandText = "Delete From TB_PermissionsAllUsers Where PathId In (" + stringListPathsId + ")";

            Commandtype = CommandType.Text;

            return Save();
        }
    }
}
